<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require_once(dirname(__FILE__) . "/../dbcom/ReservetimeCom.php");
require_once(dirname(__FILE__) . "/../common/Common.php");

$rtimecom = new ReservetimeCom();
$common = new Common();

$cont = $_REQUEST['cont'];
switch ($cont) {
    case 1://删除
        if (!isset($_REQUEST['rtimeid']) || empty($_REQUEST['rtimeid'])) {
            echo json_encode(array("code" => 100, "msg" => "cannot find rtimeid"));
            break;
        }
        $rtimeid = $_REQUEST['rtimeid'];
        $res = $rtimecom->deleteRtime($rtimeid);
        if($res){
            echo json_encode(array("code" => 0, "msg" => "success", "data"=>$rtimeid));
        }else{
            echo json_encode(array("code" => 400, "msg" => "delete failed"));
        }
        break;
    case 2://新增
        if (!isset($_REQUEST['name']) || empty($_REQUEST['name'])) {
            echo json_encode(array("code" => 100, "msg" => "cannot find name"));
            break;
        }
        $info = $_REQUEST['name'];
        $resi = $rtimecom->checkSame($info);
        if(!empty($resi)){
            echo json_encode(array("code" => 10, "msg" => "same thing"));
            break;
        }
        $res = $rtimecom->addRtime($info);
        if($res){
            echo json_encode(array("code" => 0, "msg" => "success"));
        }else{
            echo json_encode(array("code" => 400, "msg" => "add failed"));
        }
        break;
    default :
        echo json_encode(array("code" => 500, "msg" => "undefined error"));
        break;
}
exit();
